<template>
	<view>
		<!-- <view v-if="need_jump == 1" @tap="jumpNew" style="position: fixed; background: #000; opacity: 0.7; width: 100%; height: 100%; top: 0; left: 0; z-index: 999"></view> -->
		<popupwindow v-if="need_jump == 1 && live.last_qrcode_img" showClose="0" visible="1"
			:contentImage="live.last_qrcode_img" contentHeight="350" :outClickCanClose="false"></popupwindow>
		<!-- <view @tap="bindGetUserInfo" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999" v-if="live.id != 364 && userInfoCheck == 0"></view> -->


		<!-- :class="['view_bg ' + themes ,'view_bg'+themes]" -->
		<view v-if="vote"
			:style="'overflow:hidden;min-height:50vh;position:relative;padding-bottom:100rpx;background-color:' + color_two + ';'">
			<view class="content bg_white h2" style="">
				<view :class="['member_nums','w_100','menber_nums'+themes]">
					<view class="fl">
						<view class="fl iconfont icon-user-center" :style="'color:' + color_one + ';'"></view>
						<text v-if="!live.is_vote_num" class="fl p_r"
							:style="'max-width:180rpx;height:40rpx;line-height:44rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color:' + color_one + ';'">
							{{ vote_info.sort }}号
						</text>
						<text class="fl"
							:style="'max-width:180rpx;height:40rpx;line-height:44rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color:' + color_one + ';'">
							{{ vote_info.name }}
						</text>
					</view>
					<view class="fr member_vote_num"
						v-if="(vote.vote_downtime_status != 1 && vote.hide_data_before == 1) || vote.hide_data_before == 0">
						<view class="fl iconfont icon-paihang" :style="'color:' + color_one + ';'"></view>
						<text class="fl" :style="'color:' + color_one + ';'">{{ vote_index }}</text>
					</view>
					<view class="fr"
						v-if="(vote.vote_downtime_status != 1 && vote.hide_data_before == 1) || vote.hide_data_before == 0">
						<view class="fl iconfont icon-renqi1" :style="'color:' + color_one + ';'"></view>
						<text class="fl" :style="'color:' + color_one + ';'">{{ vote_info.votes }}</text>
					</view>
					<!-- <view class="fr" >
                <view class="fl iconfont icon-dianji3"></view>
                <text class="fl">{{member_detail.view_cnt||0}}</text>
            </view> -->
				</view>
				<view
					v-if="(vote.vote_downtime_status != 1 && vote.hide_data_before == 1) || vote.hide_data_before == 0">
					<text v-if="qian_duo_p">
					
						<text :class="['red_text','red_text'+themes]"
							:style="'color:' + color_one + ';'">比上一名 少{{ qian_duo_p }}</text>
						{{ columnsurs.zan }}，
					</text>
					
					<text :class="['red_text','red_text'+themes]"
						:style="'color:' + color_one + ';'">比后一名 多{{ hou_duo_p }}</text>
					{{ columnsurs.zan }}
				</view>
				<view
					v-if="((info_xuan.vote_downtime_status==1 || info_xuan.vote_downtime_status==3 ||info_xuan.vote_downtime_status==4) && info_xuan.hide_data_before==0) || ((info_xuan.vote_downtime_status2==1 || info_xuan.vote_downtime_status2==3 ||info_xuan.vote_downtime_status2==4) && info_xuan.hide_data_before2==0)"
					:class="['member_vote','w_100','rad_3','t_white','t_c','member_vote'+themes]"
					:data-xuan_id="info_xuan.id" :data-xuan_name="info_xuan.name" style="text-decoration:none"
					:style="'color:' + color_three + ';background-color:' + color_one + ';'" @tap="tsk">
					{{ columnsurs.award ? columnsurs.award : '为Ta投票' }}
				</view>
				<view v-else>
						<view @tap="bindopenvote"
							v-if="((info_xuan.vote_downtime_status != 1 && info_xuan.hide_data_before == 1) || info_xuan.hide_data_before == 0) || ((info_xuan.vote_downtime_status2 != 1 && info_xuan.hide_data_before2 == 1) || info_xuan.hide_data_before2 == 0)"
							:class="['member_vote','w_100','rad_3','t_white','t_c','member_vote'+themes]"
							:data-xuan_id="info_xuan.id" :data-xuan_name="info_xuan.name" :data-index="index"
							:data-url="info_xuan.h5_url"
							:style="'color:' + color_three + ';background-color:' + color_one + ';'">
							{{ columnsurs.award ? columnsurs.award : '打call' }}
							<!-- <image class="btn_icon_src" src="{{'../../resource/images/icon2.png'}}"></image> -->
						</view>
				</view>
				<view class="member_video">
					<audio class="m_b w_100" v-if="!(vote_info.music == '' ? true : false)" id="myAudio"
						@tap="audioClick" :src="vote_info.music" :poster="vote_info.pic" name="选手音频"
						:author="vote_info.name" controls loop></audio>
					<video class="m_b w_100" mode="widthFix" v-if="vote_info.video" :src="vote_info.video"></video>
					<image class="m_b w_100" @tap="imgYu" mode="widthFix" v-if="vote_info.pic" :src="vote_info.pic"
						:data-src="vote_info.pic"></image>
					<image class="m_b w_100" @tap="imgYu" mode="widthFix" v-if="vote_info.pic1" :src="vote_info.pic1"
						:data-src="vote_info.pic1"></image>
					<image class="m_b w_100" @tap="imgYu" mode="widthFix" v-if="vote_info.pic2" :src="vote_info.pic2"
						:data-src="vote_info.pic2"></image>
					<image class="m_b w_100" @tap="imgYu" mode="widthFix" v-if="vote_info.pic3" :src="vote_info.pic3"
						:data-src="vote_info.pic3"></image>
					<image class="m_b w_100" @tap="imgYu" mode="widthFix" v-if="vote_info.pic4" :src="vote_info.pic4"
						:data-src="vote_info.pic4"></image>
					<view class="vote_content w_100 p_s_b h2" :style="'padding:20px 0 20px 0;color:' + color_one + ';'"
						v-if="vote_info.content">
						<!-- <template is="wxParse" :data="wxParseData:vote_content.nodes"></template> -->
						<!-- <view>{{article_vote_content}}</view> -->
						<mp-html :content="article_vote_content"></mp-html>
					</view>

					<view class="w_100 p_s_b h2 judges"
						:style="'padding:20px 0 0 0;color:' + color_one + ';border-bottom:1px solid #eee;'"
						v-if="live.cha_fen_status == 1">
						<view style="padding: 15px 0px; line-height: 20px; border-top: 1px solid #eee"
							class="judges_title">
							<text style="font-size: 16px; font-weight: bold">评委点评</text>
							<text style="float: right; font-size: 14px; color: #333"
								v-if="vote_info.avg_fen > 0">得分结果：{{ vote_info.avg_fen }}分</text>
						</view>
						<view style="padding: 10px 0px; position: relative; border-top: 1px solid #eee"
							class="judges_one" v-for="(value, index) in judges" :key="index">
							<view style="padding-bottom: 10px">
								<h2 :style="'color: ' + (color_one ? color_one : '#CCAB69') + ';'">
									{{ value.admin_name }}：
								</h2>
								<text style="color: #333" v-if="value.fen > 0">{{ value.fen }}分</text>
								<text style="color: #333"
									v-if="value.ping_status > 0">{{ value.ping_status == 1 ? '晋级' : '淘汰' }}</text>
								<text style="float: right; color: #ccc; font-size: 12px">{{ value.add_time }}</text>
							</view>

							<view>评语：{{ value.content }}</view>
						</view>
					</view>
				</view>
				<view
					v-if="((info_xuan.vote_downtime_status==1 || info_xuan.vote_downtime_status==3 ||info_xuan.vote_downtime_status==4)&& info_xuan.hide_data_before == 0)||((info_xuan.vote_downtime_status2==1 || info_xuan.vote_downtime_status2==3 ||info_xuan.vote_downtime_status2==4)&& info_xuan.hide_data_before2 == 0)"
					:class="['member_vote','w_100','rad_3','t_white','t_c','member_vote'+themes]"
					:data-xuan_id="info_xuan.id" :data-xuan_name="info_xuan.name" style="text-decoration:none"
					:style="'color:' + color_three + ';background-color:' + color_one + ';'" @tap="tsk">
					{{ columnsurs.award ? columnsurs.award : '为Ta投票' }}
				</view>
				<view v-else>
						<view @tap="bindopenvote"
							v-if="((info_xuan.vote_downtime_status != 1 && info_xuan.hide_data_before == 1) || info_xuan.hide_data_before == 0) || ((info_xuan.vote_downtime_status2 != 1 && info_xuan.hide_data_before2 == 1) || info_xuan.hide_data_before2 == 0)"
							:class="['member_vote','w_100','rad_3','t_white','t_c','member_vote'+themes]"
							:data-xuan_id="info_xuan.id" :data-xuan_name="info_xuan.name" :data-index="index"
								:data-url="info_xuan.h5_url"
							:style="'color:' + color_three + ';background-color:' + color_one + ';'">
							{{ columnsurs.award ? columnsurs.award : '打call' }}
							<!-- <image class="btn_icon_src" src="{{'../../resource/images/icon2.png'}}"></image> -->
						</view>
					
				</view>

				<view :class="['member_btn','member_btn'+themes]">
					<!-- <view class="btn" hoverClass="none" @tap="refreshmovie">
					 <text class="iconfont icon-gou" :style="'color:' + color_one + ';'"></text>
				    <view class="member_btn_txt" :style="'color:' + color_one + ';'">刷 新</view>
				</view> -->
					<!-- <navigator class="btn" hoverClass="none" :url="'/wxz_wzbagent/pages/movie/movie?token=' + token">
						<text class="iconfont icon-home" :style="'color:' + color_one + ';'"></text>
						<view class="member_btn_txt" :style="'color:' + color_one + ';'">回到首页</view>
					</navigator> -->
					<view class="btn" hoverClass="none" @tap="bindSheng">
						<text class="iconfont icon-erweima" :style="'color:' + color_one + ';'"></text>
						<view class="member_btn_txt" :style="'color:' + color_one + ';'">生成海报</view>
					</view>
				</view>
			</view>
		</view>
		<view :class="'footer ' + themes" :style="'color:' + color_three + ';background-color:' + color_three + ';'">
			{{ live.footer_name }}
		</view>
		<!-- 投票框 -->
		<block v-if="vote_show_flag == true">
			<view>
				<!-- parse <template is="vote" :data="themes:themes,xuan_name:vote_info.name,xuan_id:xuan_id,vote_index:vote_index,columnsurs:columnsurs,bills:bills,id:vote_gift_id,num:vote_gift_num,flag:vote_flag,color_status,color_one,color_two,color_three"></template> -->
				<block name="vote">
					<view @tap="bindclosevote" class="cover"  style="background-color: rgb(0 0 0 / 93%);"></view>
					<view :class="'vote_module w_100 bg_white ' + themes" style="height: 60%; background-color: #fff ;line-height: 32px;"
						v-if="vote_flag == false">
						<view class="vote_title t_c h2" :style="'color:' + (color_one ? color_one : '#C8AF82') + ';'">
							支持{{ xuan_name }}
							<view class="textstyle">
								排名{{vote_index}}
							</view>
							<image @tap="bindclosevote" class="vote_close"
								src="/static/wxz_wzbagent/resource/images/icon3.png"></image>
						</view>
						<view @tap="bindbuy" :data-xuan_id="xuan_id" :data-xuan_name="vote_info.name"
							:data-index="vote_index" class="gift_buy h3 rad_3 t_white t_c m_l_t"
							:style="'color:' + (color_three ? color_three : '#fff') + ';background-color:' + (color_one ? color_one : '#C8AF82') + ';'">
							{{ columnsurs.award ? columnsurs.award : '为Ta投票' }}
						</view>
						<view class="vote_content">
							<view class="vote_gift t_gray9 h4 t_c">
								<view @tap="bindchoosegift" class="gift_item m_b" :data-ballot="item.ticket"
									:data-id="item.id" data-type="bills" v-for="(item, index) in bills" :key="item.id">
									<view class="gift_img rad_5"
										style="width: 100rpx; height: 100rpx; margin-left: 30rpx; border: 2rpx solid #ccc">
										<image class="w_100 h_100 rad_5" :src="item.pic"></image>
										<view class="gift_choose iconfont icon-xuanzhong"
											:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'"
											v-if="item.id == vote_gift_id"></view>
									</view>

									<view :style="'color:' + (color_one ? color_one : '#C8AF82') + ';'">
										{{ item.ticket }}{{ columnsurs.zan ? columnsurs.zan : '票' }}
									</view>

									<view class="gift_money"
										:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'"
										v-if="item.amount == 0">免费</view>

									<view class="gift_money"
										:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'" v-else>
										<span v-if="money_flag">￥</span>
										<span v-else>$</span>{{ item.amount / 100 }}
									</view>
								</view>
							</view>
							<!-- <view class="prize_title" style="background-color:{{themeColor.vote_layer.goods.bg}};color:{{themeColor.vote_layer.goods.header}};" wx:if="{{vote_product.goods}}">
                <view class="prize_title_txt">
                    <view class="prize_left_line" style="background-color:{{themeColor.vote_layer.goods.header}};"></view>
                    <view class="prize_right_line" style="background-color:{{themeColor.vote_layer.goods.header}};"></view>
                    投{{data.tip_text.tip_unit?data.tip_text.tip_unit:'票'}}
                </view>
            </view> -->
							<!-- <view class="vote_gift vote_gift_num_{{vote_product.goods.length}} h4 vote_prize" style="background-color:{{themeColor.vote_layer.goods.bg}};" wx:if="{{vote_product.goods}}">
                <view bindtap="bindchoosegift" class="gift_item " data-ballot="{{item.vote_count}}" data-id="{{item.id}}" data-is_send="{{item.is_send}}" data-type="goods" wx:for="{{vote_product.goods}}" wx:key="id">
                    <view class="gift_img {{item.id==id?'active':''}} {{vote_product.goods.length>4?'goodsLength':''}}">
                        <image class="w_100 h_100" src="{{item.product_cover}}" wx:if="{{vote_product.goods.length<=4}}"></image>
                        <image class="w_100" mode="scaleToFill" src="{{item.product_cover}}" wx:else></image>
                        <view class="choose_img">
                            <view class="iconfont icon-gou" style="color:{{themeColor.vote_layer.goods.icon}};" wx:if="{{item.id==id}}"></view>
                        </view>
                    </view>
                    <view class="gift_gname" style="color:{{themeColor.vote_layer.goods.txt1}};">{{item.product_name}}</view>
                    <view class="gift_txt t_green" style="color:{{themeColor.vote_layer.goods.txt2}};">
                            {{item.vote_count}}{{data.tip_text.tip_unit?data.tip_text.tip_unit:'票'}}
                        </view>
                    <view class="gift_money" style="color:{{themeColor.vote_layer.goods.txt3}};">
                            {{item.money/100}}{{data.tip_text.tip_currency}}
                        </view>
                </view>
            </view> -->
							<view class="gift_num_label w_100 h4 t_gray9 t_c m_b"
								:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'">
								<span v-if="money_flag">请选择礼物数量</span>
								<span v-else>Please select a gift quantity</span>
							</view>
							<view class="gift_num t_c b_all rad_3">
								<view @tap="bindgiftnum" class="gift_btn fl" data-type="-1"
									:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'">
									<view class="iconfont icon-sub"
										:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'"></view>
								</view>
								<view class="gift_txt fl h2"
									:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'">
									<input type="number" @input="bindchangenum" :value="vote_gift_num"
										style="height: 76rpx; line-height: 76rpx; width: 100%; text-align: center" />
								</view>
								<view @tap="bindgiftnum" class="gift_btn fl" data-type="1"
									:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'">
									<view class="iconfont icon-jiahao"
										:style="'color:' + (color_one ? color_one : '#C8AF82') + ';'"></view>
								</view>
							</view>
							<!-- <text class="buy_txt" style="color:#C8AF82;"></text> -->
						</view>
					</view>

					<!-- <view class="prompt bg_white" wx:if="{{flag==true}}">
        <view class="prompt_bg">
            <image class="prompt_header" src="../../statics/image/icon37.png"></image>
            <image bindtap="bindclosevote" class="prompt_close" src="../../statics/image/icon32.png"></image>
            <image class="prompt_img" src="{{banner_img?banner_img:''}}" wx:if="{{banner_img}}"></image>
            <text class="prompt_tip h3 t_gray6 t_c m_t">{{vote_gift_type=='goods'?vote_gift_is_send==1?'您的礼物已经在准备':'您的礼物需要到店兑换':vote_success_msg}}</text>
            <text class="prompt_tip h3 t_gray6 t_c m_b" wx:if="{{vote_gift_type=='goods'}}">{{vote_gift_is_send==1?'请填写收货地址~':'可以前往我的订单页面查看'}}</text>
            <view bindtap="my" class="prompt_btn bg_green t_c t_white h3 rad_3" style="background-color:#FFAE21" wx:if="{{vote_gift_type=='goods'}}">{{vote_gift_is_send==1?'填写收货地址':'查看我的订单'}}</view>
            <view bindtap="bindclosevote" class="prompt_btn bg_green t_c t_white h3 rad_3" style="background-color:#FFAE21" wx:else>确定</view>
            <view bindtap="toMini" class="banner_img" data-appid="{{banner.appid}}" data-extra="{{banner.extra}}" data-path="{{banner.link}}" wx:if="{{banner}}">
                <image src="{{banner.image}}"></image>
            </view>
            <cover-view class="agg_img m_t" wx:if="{{banner==undefined&&agg}}">
                <ad unitId="{{agg}}"></ad>
            </cover-view>
        </view>
    </view> -->
				</block>
			</view>
		</block>

		<view @longpress="touchsave" class="shareCanvas" style="width: 90%; height: 80%" v-if="share_flag == true">
			<canvas canvasId="shareCanvas" style="width: 100%; height: 100%"></canvas>
			<cover-view class="savepromot">长按图片保存到手机</cover-view>
			<button @tap="bindopensetting" class="openSetting" openType="openSetting" v-if="openSetting"></button>
		</view>

		<view class="vote_convas" v-if="voteMaskLi">
			<view class="vote_convas_conent">
				<view class="vote_convas_title" :style="'color:' + color_three + ';'">
					请选择海报模板
					<image @tap="voteMaskClose" class="vote_convas_close" data-index="1"
						src="/static/wxz_wzbagent/resource/images/icon3.png"></image>
				</view>
				<view class="vote_convas_main">
					<view @tap="voteConvasLi" :class="'vote_convas_li vote_convas_active' + item" :data-index="item"
						:style="'background-image: url(' + voteBg[item] + ')'" v-for="(item, index) in 9" :key="index">
						<view class="voteLi_title">{{ vote_info.name }}</view>

						<view class="voteLi_content">{{ live.f_title_1 }}{{ vote_info.name }}{{ live.f_title_2 }}</view>

						<view class="voteLi_img">
							<image mode="widthFix" :src="vote_info.pic"></image>
						</view>

						<image class="voteLi_img_bottom" mode="widthFix" :src="voteBgActive[item]"
							v-if="voteBgActive[item]"></image>

						<image class="voteLi_img_erweima" :src="sunEwm"></image>

						<view class="voteLi_text1">请识别二维码</view>

						<view class="voteLi_text2">长按图片保存到手机</view>
					</view>
				</view>
			</view>
		</view>
		<!-- @click="touchStart()" -->
		<view class="vote_mask" @longpress="saveCanvas" v-show="voteMask">
			<!-- #ifdef H5 -->
			<img :src="haibaoimg" v-show="haibaoimgshow"
				style="position: absolute;width: 96%;z-index: 9999;transform: translateX(-50%) translateY(-50%);-webkit-transform: translateX(-50%) translateY(-50%);top: 50%;left: 50%;"></img>
			<!-- #endif -->
			<canvas canvasId="voteCanvas" class="my-canvas" style="left: 9999px;"></canvas>
			<cover-image @tap="voteMaskClose" class="vote_mask_img" data-index="2"
				src="/static/wxz_wzbagent/resource/images/icon3.png" style="z-index: 10000"></cover-image>
		</view>
		<view @tap="bindclosevote" class="cover" v-if="share_flag == true"></view>
	</view>
</template>

<script>
	function e(e, a) {
		console.log(e, 'eeeeee');
		e.setData({
			memberImg: e.vote_info.pic,
			qrcodeImg: e.sunEwm
		});
		uni.showLoading({
			title: '正在生成海报...'
		})
		t(e, a);
		// var i = '' + e.vote_info.pic;
		// var o = e.sunEwm;
		// if ('' == e.memberImg || '' == e.qrcodeImg) {
		// 	uni.downloadFile({
		// 		url: i,
		// 		success: function(i) {
		// 			uni.hideLoading();
		// 			console.log(e,'eeee');
		// 			if (200 == i.statusCode) {
		// 				uni.showLoading({
		// 					title: '正在下载图片'
		// 				});
		// 				console.log(i);
		// 				uni.downloadFile({
		// 					url: o,
		// 					success: function(o) {
		// 						console.log(o,'000000000');
		// 						uni.hideLoading();
		// 						if (200 == o.statusCode) {
		// 							e.setData({
		// 								memberImg: i.tempFilePath,
		// 								qrcodeImg: o.tempFilePath
		// 							});
		// 							t(e, a);
		// 						} else {
		// 							showError('下载图片失败');
		// 						}
		// 					}
		// 				});
		// 			} else {
		// 				showError('下载图片失败');
		// 			}
		// 		}
		// 	});
		// } else {
		// 	t(e, a);
		// }
	}

	function t(e, t) {
		if (void 0 == e.wxVoteBg[t]) {
			uni.downloadFile({
				url: e.voteBg[t],
				success: function(i) {
					uni.hideLoading();
					if (200 == i.statusCode) {
						if (void 0 == e.voteBgActive[t]) {
							var o = e.wxVoteBg;
							o[t] = i.tempFilePath;
							e.setData({
								wxVoteBg: o
							});
							return void a(e, t);
						}
						uni.showLoading({
							title: '正在下载图片'
						});
						uni.downloadFile({
							url: e.voteBgActive[t],
							success: function(o) {
								uni.hideLoading();
								if (200 == o.statusCode) {
									var s = e.wxVoteBg;
									s[t] = i.tempFilePath;
									var n = e.wxVoteBgActive;
									n[t] = o.tempFilePath;
									e.setData({
										wxVoteBg: s,
										wxVoteBgActive: n
									});
									a(e, t);
								} else {
									showError('下载图片失败');
								}
							}
						});
					} else {
						showError('下载图片失败');
					}
				}
			});
		} else {
			a(e, t);
		}
	}

	function a(e, t) {
		uni.showLoading({
			title: '正在生成海报...'
		})
		var a = uni.createSelectorQuery();
		a.select('.my-canvas').boundingClientRect();
		a.exec(function(a) {
			console.log(a);
			var n = a[0].height;
			var d = a[0].width;
			var c = e.memberImg;
			var r = e.qrcodeImg;
			var l = e.vote_info.name;
			var g = e.live.f_title_1 + e.vote_info.name + e.live.f_title_2;
			var h = {};
			if (void 0 != e.wxVoteBgActive[t]) {
				uni.getImageInfo({
					src: e.wxVoteBgActive[t],
					success: function(e) {
						h = {
							width: e.width,
							height: e.height
						};
					}
				});
			}
			uni.getImageInfo({
				src: c,
				success: function(a) {
					var u = uni.createCanvasContext('voteCanvas');
					//var u = canvas.getContext("voteCanvas");
					u.setFillStyle('#FFFFFF');
					u.fillRect(0, 0, d, n);
					u.drawImage(e.wxVoteBg[t], 0, 0, d, n);
					u.setFontSize(18);
					u.setFillStyle(e.canvasColor[t]);
					u.setTextAlign('center');
					u.fillText(l, parseInt(d / 2), 30); //console.log(d,n);//260.14 352
					//console.log(c);
					var f = 0.82 * d;
					var m = 0.72 * n;
					var _ = 1 != t ? 90 : 40;
					let imgWidth = d * 0.817 - 7.5;
					let imgHeight = n * 0.719 - 8;
					let imgScale = imgWidth / imgHeight;
					let nowScale = a.width / a.height;
					var visibleX;
					var visibleY = 0;
					if (imgScale < nowScale) {
						let newW = (imgHeight / a.height) * a.width;
						//console.log(newW, a.width, imgWidth);
						const bili = newW / a.width;
						visibleX = Math.abs(imgWidth - newW) / 2 / bili;
						visibleY = 0;
						a.width = (imgWidth * a.height) / imgHeight;
					} else {
						visibleX = 0;
						let newH = (imgWidth * a.height) / a.width;
						const bili = newH / a.height;
						visibleY = Math.abs(imgHeight - newH) / 2 / bili;
						a.height = (a.width * imgHeight) / imgWidth;
					}
					// console.log(imgScale,nowScale);
					// console.log(visibleX,visibleY);

					//console.log(d,n);
					u.fillRect((d - f) / 2, _, f, m);
					if (a.height > 500) {
						_ = _;
					} else {
						_ = _ + (m - a.height / 2) / 2;
					}
					if (a.height > 500) {
						f = f;
					} else {
						f = a.width / 2;
					}
					if (a.height > 500) {
						m = m;
					} else {
						m = a.height / 2;
					}
					//console.log((d - f) / 2 + 4, _ + 4);
					u.drawImage(c, visibleX, visibleY, a.width, a.height, (d - f) / 2 + 4, _ + 4,
						imgWidth, imgHeight);
					if (void 0 != e.wxVoteBgActive[t]) {
						u.drawImage(e.wxVoteBgActive[t], 0, n - h.height / 2, 2 == t ? 0.94 * d : d, h
							.height / 2);
					}
					// 左下广告 u.drawImage('../../resource/images/azbg.jpg', 5, n - 91.2 - 5, 162, 91.2),
					ss({
							context: u,
							index: t,
							q_img: r
						},
						d,
						n
					);
					u.setTextAlign('left');
					i({
						ctx: u,
						fontSize: 14,
						word: g,
						maxWidth: d - 60,
						x: 30,
						y: 1 != t ? 30 : n - 58,
						//40 : n - 50
						maxLine: 3
					});
					u.draw(false, function() {
						o(e, d, n, 1);
					});
				}
			});
		});
	}

	function i(e) {
		uni.showLoading({
			title: '正在生成海报...'
		})
		e.ctx.setFontSize(e.fontSize);
		for (var t = Math.ceil(e.ctx.measureText(e.word).width / e.maxWidth), a = t >= e.maxLine ? e.maxLine : t, i = 0,
				o = 0; o < a; o++) {
			var s = e.word.slice(i);
			var n = 0;
			if (e.ctx.measureText(s).width > e.maxWidth) {
				for (var d = 0; d < s.length; d++) {
					if ((n += e.ctx.measureText(s[d]).width) > e.maxWidth) {
						if (o === e.maxLine - 1) {
							e.ctx.fillText(s.slice(0, d - 1) + '...', e.x, e.y + 18 * (o + 1));
						} else {
							e.ctx.fillText(s.slice(0, d), e.x, e.y + 18 * (o + 1));
						}
						i += d;
						break;
					}
				}
			} else {
				e.ctx.fillText(s.slice(0), e.x, e.y + 18 * (o + 1));
			}
		}
	}

	function o(e, t, a, i) {
		uni.showLoading({
			title: '正在生成海报...'
		})
		uni.canvasToTempFilePath({
			x: 0,
			y: 0,
			width: t,
			height: a,
			destWidth: 5 * t,
			destHeight: 5 * a,
			quality: 1,
			canvasId: 'voteCanvas',
			success: function(t) {
				var a = {};
				a[e.canvasIndex] = t.tempFilePath;
				e.setData({
					canvasFilePaths: a
				});
				e.setData({
					haibaoimg: a[e.canvasIndex],
					haibaoimgshow: true,
					voteMask: true
				});
				uni.hideLoading()
			},
			fail: function(o) {
				if (++i < 30) {
					c(e, t, a, i);
				}
			}
		});
	}

	function ss(e, t, a) {
		uni.showLoading({
			title: '正在生成海报...'
		})
		var i = 'right';
		var o = 0;
		var s = 0;
		if (1 == e.index) {
			s = 60;
		} else {
			if (2 == e.index || 4 == e.index || 5 == e.index || 6 == e.index || 7 == e.index) {
				s = -10;
			} else {
				e.index || ((i = 'left'), (o = 105), 8 == e.index ? (s = 0) : (s = -10), 8 == e.index && e.context
					.setFillStyle('#27347D'));
			}
		}
		if (3 == e.index || 8 == e.index) {
			e.context.drawImage(e.q_img, 28, a - 150 - s, 130, 130);
		} else {
			e.context.drawImage(e.q_img, t - 150 - o, a - 150 - s, 130, 130);
		}
		// e.context.setTextAlign(i);
		// e.context.setFontSize(10);
		// e.context.fillText('请识别二维码', t - 107 - o, a - 40 - s, t);
		if (8 == e.index) {
			e.context.setFillStyle('#fff');
		}
	}

	function n(e) {
		var t = e.canvasFilePaths[e.canvasIndex];
		console.log(t);
		uni.saveImageToPhotosAlbum({
			filePath: t,
			success: function(t) {
				showError('成功保存到手机');
				e.setData({
					voteMask: false
				});
			},
			fail: function(e) {
				console.log('saveImageToPhotosAlbum fail');
				console.log(e);
			}
		});
	}

	function d(e) {
		var t = g.cget('member_id_' + e.member_id);
		uni.saveImageToPhotosAlbum({
			filePath: t,
			success: function(t) {
				e.setData({
					share_flag: false
				});
				showError('成功保存到手机');
			},
			fail: function(e) {
				console.log('saveImageToPhotosAlbum fail');
				console.log(e);
			}
		});
	}

	function c(e, t, a, i) {
		uni.canvasToTempFilePath({
			x: 0,
			y: 0,
			width: t,
			height: a,
			destWidth: 5 * t,
			destHeight: 5 * a,
			quality: 1,
			canvasId: 'shareCanvas',
			success: function(t) {
				console.log({
					0: t.tempFilePath
				});
				g.cset('member_id_' + e.member_id, t.tempFilePath);
			},
			fail: function(o) {
				if (++i < 30) {
					c(e, t, a, i);
				}
			}
		});
	}

	function showError(t) {
		uni.hideToast();
		uni.showModal({
			title: '提示',
			content: t,
			showCancel: false
		});
	}
	var app = getApp();
	import popupwindow from '@/component/popupwindow/popupwindow.vue';
	export default {
		components: {
			popupwindow
		},
		props: {
			xuan_id: {
				type: String, //定义传值类型
				default: "1"
			},
			token: {
				type: String, //定义传值类型
				default: ""
			},
			info_xuan: {
				type: Object,
				default: ""
			},
			live:{
				type: Object,
				default: ""
			},
			document_url:{
				type: String,
				default: ""
			}
		},
		created() {
			
			this.getCode();
			this.get_vote_info();
			if (isWeiXin()) {
				console.log('当前是微信')
				this.phonewx = true
			} else if (/AlipayClient/.test(window.navigator.userAgent)) {
				console.log('当前是支付宝')
			} else {
				this.money_flag = false
				console.log(/AlipayClient/.test(window.navigator.userAgent), 22222)
			}
			console.log('父组件data定义的变量包含函数', this.xuan_id, this.token, this.info_xuan,this.live);
			this.uniacid= this.live.uniacid,
			this.rid= this.live.rid,
			this.live_id= this.live.id,
			this.color_status=this.live.color_status,
			this.color_one= this.live.color_one,
			this.color_two= this.live.color_two,
			this.color_three= this.live.color_three
			this.share(this.token, this.xuan_id);
			this.vote_info = this.info_xuan
			if (this.info_xuan.vote_downtime_status2 > 0) {
				this.vote.vote_downtime_status = this.info_xuan.vote_downtime_status2
				this.vote.hide_data_before = this.info_xuan.hide_data_before2
			} else {
				this.vote.vote_downtime_status = this.info_xuan.vote_downtime_status
				this.vote.hide_data_before = this.info_xuan.hide_data_before
			}
			
		},

		data() {
			return {
				phonewx: false,
				money_flag: true,
				haibaoimg: "",
				haibaoimgshow: false,
				index: 0,
				// xuan_id: 0,
				live_id: 0,
				rid: 0,
				uniacid: 0,
				wxapp_id: 0,

				//当前链接所使用小程序
				vote_index: 0,

				columnsurs: {
					award: false,
					zan: false
				},

				// live: {
				// 	last_qrcode_img: '',
				// 	id: 0,
				// 	is_vote_num: '',
				// 	cha_fen_status: 0,
				// 	footer_name: '',
				// 	f_title_1: '',
				// 	f_title_2: ''
				// },

				judges: {},
				themes: '',

				//主题
				vote_info: {
					sort: '',
					name: '',
					votes: '',
					id: '',
					music: '',
					pic: '',
					video: '',
					pic1: '',
					pic2: '',
					pic3: '',
					pic4: '',
					content: '',
					avg_fen: 0
				},

				//投票框数据
				bills: {},

				//礼物
				vote_show_flag: false,

				//显示投票框
				vote_flag: false,

				//显示投票框
				vote_gift_open: 0,

				//显示投票框
				vote_gift_id: 0,

				//礼物id
				vote_gift_num: 1,

				//礼物数量
				//海报数据
				voteMaskLi: false,

				voteMask: false,
				sunEwm: '',
				voteBg: {},
				voteBgActive: {},
				share_flag: 0,
				openSetting: false,
				imgView: '?imageView2/1/w/529/h/678',
				memberImg: '',
				qrcodeImg: '',
				canvasIndex: '',
				userInfoCheck: 0,

				canvasColor: {
					0: '#fff',
					1: '#fff',
					2: '#000',
					3: '#fff',
					4: '#FBDE3D',
					5: '#E0BF6E',
					6: '#fff',
					7: '#E0BF6E',
					8: '#fff'
				},

				wxVoteBg: {},
				wxVoteBgActive: {},
				canvasFilePaths: {},
				isPlaying: false /*音频播放 */ ,
				// token: '',
				rk_uid: '',
				is_black: '',
				jump_appid: '',
				need_jump: 0,

				vote: {
					vote_downtime_status: 0,
					hide_data_before: 0
				},

				qian_duo_p: '',
				hou_duo_p: '',
				color_status: '',
				color_one: '',
				color_two: '',
				color_three: '',
				xuan_name: '',
				article_vote_content: '',

				value: {
					admin_name: '',
					fen: 0,
					ping_status: 0,
					add_time: '',
					content: ''
				}
			};
		}
		/**
		 * 生命周期函数--监听页面加载
		 */
		,
		onShow: function() {
			console.log(111)
			uni.hideHomeButton();
		},
		onReady: function(e) {
			console.log(111)
			this.audioCtx = uni.createAudioContext('myAudio');
		},
		onUnload: function() {
			console.log(111)
			//this.innerAudioContext.destroy();
		},
		onLoad: function(options) {
			// #ifdef H5
			//if(isWeiXin()){
			this.getCode();
			//  }
			// #endif
			console.log(1111)
			
			var that = this;
			const scene = decodeURIComponent(options.scene);
			//wx.hideShareMenu({})
			if (scene !== 'undefined') {
				scene.split('&').forEach((item) => {
					var key = item.split('=')[0];
					if (key == 'x') {
						key = 'xuan_id';
					}
					if (key == 't') {
						key = 'token';
						that.login(item.split('=')[1], '', '', '');
					}
				});
				that.get_vote_info();
			} else {
				if (options.x && options.t && options.x != 'undefined' && options.t != 'undefined') {
					that.setData({
						xuan_id: options.x,
						token: options.t,
						rk_uid: options.rk_uid
					});
					that.login(options.x, options.share_uid, options.from, options.rk_uid);
				} else {
					that.setData({
						xuan_id: options.xuan_id,
						token: options.token,
						rk_uid: options.rk_uid
					});
					that.login(options.token, options.share_uid, options.from, options.rk_uid);
				}
				that.get_vote_info();
			}
			const userInfo = uni.getStorageSync('uid');
			if (userInfo) {
				that.setData({
					userInfoCheck: 1
				});
			}
		},
		//小程序分享
		onShareAppMessage: function() {
			return {
				//title: this.data.live.f_title_1 + this.data.vote_info.name + this.data.live.f_title_2,
				title: this.live.share_title ? this.live.share_title : this.live.title,
				path: '/wxz_wzbagent/pages/vote/vote_info?xuan_id=' + this.xuan_id + '&token=' + this.token +
					'&index=' + this.vote_index
			};
		},
		onShareTimeline: function() {
			return {
				//title: this.data.live.f_title_1 + this.data.vote_info.name + this.data.live.f_title_2,
				title: this.live.share_title ? this.live.share_title : this.live.title,
				path: '/wxz_wzbagent/pages/vote/vote_info?xuan_id=' + this.xuan_id + '&token=' + this.token +
					'&index=' + this.vote_index
			};
		},
		onPullDownRefresh() {
			location.reload();
			uni.stopPullDownRefresh();
		},
		mounted() {
			const s = document.createElement('script');
			s.type = 'text/javascript';
			s.src = 'https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js';
			document.body.appendChild(s);
			window.onload = () => { //初始化产生一个全局变量 AlipayJSBridge
				this.readys()
			}
		},
		methods: {
			readys(callback) {
				console.log(window)
				if (window.AlipayJSBridge) {
					callback && callback();
				} else {
					document.addEventListener('AlipayJSBridgeReady', callback, false);
				}
			},
			tradePay(tradeNO) {
				// 通过传入交易号唤起快捷调用方式(注意tradeNO大小写严格)
				const that = this
				AlipayJSBridge.call("tradePay", {
					tradeNO: tradeNO //tradeNO.reserved_transaction_id
				}, function(data) {
					//alert(JSON.stringify(data));
					that.setData({
						vote_show_flag: false
					});
					if (data.resultCode == 9000) {
						uni.showToast({
							title: '支付成功!',
							icon: 'none',
							success() {
								setTimeout(() => {
									location.reload();
								}, 1000)
							}
						})
					} else {
						uni.showToast({
							title: '支付失败!',
							icon: 'none'
						})
					}
				});
			},
			refreshmovie() {
				location.reload();
			},
			audioClick(e) {
				this.setData({
					isPlaying: !this.isPlaying
				});
				if (this.isPlaying) {
					this.audioCtx.play();
					console.log('播放');
				} else {
					this.audioCtx.pause();
				}
			},

			login: function(liveId, share_uid, from, rk_uid) {
				// #ifdef H5
				if (isWeiXin()) {
					let wxopenid = uni.getStorageSync('wxopenid');
					if (!wxopenid) {
						this.getCode();
					}
				}
				// #endif
				// #ifndef H5
				var that = this;
				uni.login({
					success(res) {
						if (res.code) {
							app.globalData.util.request({
								url: 'login_new&op=black_check',
								data: {
									live_id: liveId,
									code: res.code,
									share_uid: share_uid,
									from: from,
									rk_uid: rk_uid
								},
								cachetime: '0',
								showLoading: true,
								success: function(t) {
									if (t.data.data.uid) {
										uni.setStorageSync('uid', t.data.data.uid);
										return t.data.data.uid;
									}
									if (t.data.data.is_black == 1 || t.data.data.is_black == '0') {
										that.setData({
											is_black: t.data.data.is_black
										});
									}
								}
							});
						} else {
							console.log('登录失败！' + res.errMsg);
						}
					}
				});
				// #endif
			},
			//得到code
			bindGetUserInfo: function(e) {
				// var that = this;
				// uni.getUserProfile({
				//     desc: '用于完善会员资料',
				//     // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
				//     success: (res) => {
				//         //存入信息
				//         uni.setStorageSync('userInfo', res.userInfo);
				//         that.setData({
				//             userInfoCheck: 1
				//         });
				//         //授权成功后,把信息插入数据库获取uid
				//         that.login__(res);
				//     }
				// });
			},

			login__: function(info) {
				var that = this;
				uni.login({
					success(res) {
						if (res.code) {
							app.globalData.util.request({
								url: 'login_new',
								data: {
									token: that.token,
									code: res.code,
									info: info
								},
								cachetime: '0',
								showLoading: true,
								success: function(t) {
									if (t.data.errno == 0) {
										uni.setStorageSync('uid', t.data.data.uid);
									}
								}
							});
						} else {
							console.log('登录失败！' + res.errMsg);
						}
					}
				});
			},


			tsk() {
				var title = "活动还未开启"
				if (this.vote.vote_downtime_status != 1) {
					title = "活动已结束"
				}
				uni.showToast({
					title: title,
					icon: 'none',
					duration: 1500
				});
			},

			get_vote_info: function() {
				console.log(this.xuan_id)
				var that = this;
				app.globalData.util.request({
					url: 'lives_new&r=vote_info',
					data: {
						xuan_id: that.xuan_id,
						token: that.token,
						uid: uni.getStorageSync('uid'),
						wxopenid: uni.getStorageSync('wxopenid'),
						uniacid: uni.getStorageSync('uniacid'),
					},
					cachetime: '0',
					showLoading: 0,
					success: function(res) {
						//console.log(res); //获得投票信息
						//判断是否自定义颜色
						if (res.data.data.live.color_status && res.data.data.themes != '7') {
							res.data.data.themes < 7;
						} else {
							res.data.data.live.color_one = '';
							res.data.data.live.color_two = '';
							res.data.data.live.color_three = '';
						}
						var a = res.data.data;
						// if (a.live.wxapp_id != getApp().globalData.siteInfo.wxapp_id) {
						//     that.setData({
						//         jump_appid: a.live.wxapp_id,
						//         need_jump: 1,
						//         live: res.data.data.live
						//     });
						//     if (a.live.jump_force == 0) {
						//         return;
						//     }
						// }
						that.setData({
							columnsurs: res.data.data.columnsurs,
							vote_info: res.data.data.vote_info,
							bills: res.data.data.bills,
							live: res.data.data.live,
							vote: res.data.data.vote,
							judges: res.data.data.judges,
							themes: 'themes_' + res.data.data.themes,
							wxapp_id: res.data.data.live.wxapp_id,
							qian_duo_p: res.data.data.qian_duo_p,
							hou_duo_p: res.data.data.hou_duo_p,
							vote_index: res.data.data.vote_index,
							// uniacid: res.data.data.live.uniacid,
							// rid: res.data.data.live.rid,
							// live_id: res.data.data.live.id,
							token: res.data.data.live.token,
							// color_status: res.data.data.live.color_status,
							// color_one: res.data.data.live.color_one,
							// color_two: res.data.data.live.color_two,
							// color_three: res.data.data.live.color_three
						});
						// if(res.data.data.themes==7){
						// 		that.setData({
						// 			color_one:'#150A44'
						// 		})
						// }
						console.log(res.data.data.live);
						//设置页面标题
						uni.setNavigationBarTitle({
							title: that.vote_info.name
						});
						//格式化选手简介
						//wxParse.wxParse('vote_content', 'html', res.data.data.vote_info.content, that, 5)
						//that.article_vote_content = that.escape2Html(res.data.data.vote_info.content.replace(/↵/g,"<br/>") );
						that.article_vote_content = that.vote_info.content.replace(
							/(\r\n|\n|\r)/gm, "</br>");
						console.log(that.article_vote_content, 'that.article_vote_content');
					}
				});
			},

			check_appId: function() {
				var that = this;
				/* 判断当前小程序是否正常 */
				var accountInfo = uni.getAccountInfoSync();
				var appId = accountInfo.miniProgram.appId;
				app.globalData.util.request({
					url: 'lives_new&r=get_appid',
					data: {
						rid: that.rid,
						live_id: that.live_id
					},
					cachetime: '0',
					showLoading: true,
					success: function(t) {
						var appid = t.data.data.appid;
						if (appId !== appid) {
							/* 跳转到最新的小程序 */
							uni.navigateToMiniProgram({
								appId: appid,
								path: '/wxz_wzbagent/pages/movie/movie' + '?token=' + that.token,
								success(res) {
									// 打开成功
								}
							});
						}
					}
				});
			},

			//打call
			bindopenvote: function(t) {
				var that = this;
				var id = t.currentTarget.dataset.xuan_id;
				var xuan_name = t.currentTarget.dataset.xuan_name;
				var index = t.currentTarget.dataset.index;
				let url=t.currentTarget.dataset.url;
				// //判断当前小程序状态
				// if (that.live.close_pay_status == 0) {
				//     that.check_appId();
				// }
				//判断是否授权登录
				var uid = uni.getStorageSync('uid');
				// if (!uid) {
				//     that.login(that.live.token, '', '', that.rk_uid);
				// }
				// if (!uid) {
				//     uni.showToast({
				//         title: '加载中...',
				//         icon: 'none',
				//         duration: 1000
				//     });
				// } else {
				//     that.setData({
				//         vote_show_flag: true,
				//         vote_gift_open: 1,
				//         xuan_name: xuan_name,
				//         xuan_id: id
				//     });
				//return;
				//}
				if (that.payment_paypal_id != 1 && that.phonewx && url && url != 'undefined') {
					// window.location.assign(url)
					// return
				}
				app.globalData.util.request({
					url: isWeiXin() ? 'lives_new&r=poll' : 'ali&r=poll',
					data: {
						rid: that.rid,
						live_id: that.live_id,
						id: id,
						uid: uni.getStorageSync('uid'),
						wxopenid: uni.getStorageSync('wxopenid'),
						uniacid: uni.getStorageSync('uniacid'),
					},
					cachetime: '0',
					showLoading: true,
					success: function(t) {
						console.log(t);
						var json = t.data.data;
						if (json.s == 0) {
							//不能投
							uni.showToast({
								title: json.msg,
								icon: 'none',
								duration: 1500
							});
						}
						if (json.s == 8) {
							//免费票成功
							uni.showToast({
								title: json.msg,
								icon: 'none',
								duration: 1500
							});
							var zanshu = parseInt(that.vote_info.votes) + 1;
							var key = 'vote_info.votes';
							that.vote_info.votes = zanshu;
						}
						if (isWeiXin() && that.live.close_pay_status == 1) {
							uni.showModal({
								title: '提示',
								content: that.live.close_pay_tip
							});
							return false;
						}
						if (!isWeiXin() && that.live.close_pay_status_ali == 1) {
							uni.showModal({
								title: '提示',
								content: that.live.close_pay_tip
							});
							return false;
						}

						if (json.s == 1 || json.s == 2 || json.s == 3 || json.s == 4) {
							//弹出礼物框
							that.setData({
								vote_show_flag: true,
								vote_gift_open: 1,
								xuan_name: xuan_name,
								xuan_id: id
							});
							uni.showToast({
								title: json.msg,
								icon: 'none',
								duration: 1500
							});
						}
						that.get_vote_info();
					}
				});
			},

			//关闭投票弹窗
			bindclosevote: function() {
				this.setData({
					vote_show_flag: false,
					vote_flag: false
				});
			},

			//改变礼物数量
			bindgiftnum: function(t) {
				var e = t.currentTarget.dataset.type;
				var a = this.vote_gift_num;
				if (-1 == e) {
					a--;
				} else {
					a++;
				}
				if (a < 1) {
					a = 1;
				}
				this.setData({
					vote_gift_num: a
				});
			},

			//输入框改变礼物数量
			bindchangenum: function(t) {
				var e = t.detail.value;
				e = parseInt(e);
				this.setData({
					vote_gift_num: e
				});
			},

			//选中礼物
			bindchoosegift: function(t) {
				var e = t.currentTarget.dataset;
				this.setData({
					vote_gift_id: e.id,
					vote_gift_num: 1
				});
			},

			//提交打call
			bindbuy: function(t) {
				var that = this;
				var e = t.currentTarget.dataset;
				if (that.vote_gift_id) {
					if (that.vote_gift_num < 1) {
						uni.showToast({
							title: '礼物数量不能小于1件!',
							icon: 'none',
							duration: 1500
						});
					} else {
						//请求
						var gift_id = that.vote_gift_id;
						var gift_num = that.vote_gift_num;
						var uid = uni.getStorageSync('uid');
						var xuan_id = e.xuan_id;
						var voteName = e.xuan_name;
						var index = e.index;
						if (isWeiXin()) {
							// if (that.live.current_pay == -1) {
							// 	var payIframeUrl =
							// 		"http://www.pourfirst.cn/app/wxapp.php?i=9&v=2.3.0&from=wxapp&m=wxz_wzbagent&do=wechat&r=unifyPayIframe&token=" +
							// 		that.live.token + "&c=entry&a=wxapp&uid=" + uid + "&gift_id=" + gift_id +
							// 		"&gift_num=" + gift_num + "&xuan_id=" + xuan_id + "&voteName=" + voteName +
							// 		"&uniacid=" + that.live.uniacid + "&wxopenid=" + uni.getStorageSync('wxopenid') +
							// 		"&vote_index=" + index;
							// 	//console.log(payIframeUrl);
							// 	window.location.href = payIframeUrl;
							// 	return;
							// }

							//#ifdef H5
							if (isWeiXin()) {
								let wxopenid = uni.getStorageSync('wxopenid');
								if (wxopenid) {
									app.globalData.util.request({
										url: 'wechat&r=unifyPay',
										data: {
											gift_id: gift_id,
											gift_num: gift_num,
											xuan_id: xuan_id,
											voteName: voteName,
											wxapp_id: that.wxapp_id,
											uid: uni.getStorageSync('uid'),
											wxopenid: uni.getStorageSync('wxopenid'),
											uniacid: uni.getStorageSync('uniacid'),
											
										},
										cachetime: '0',
										showLoading: 0,
										success: function(t) {
											//H5微信浏览器支付
											console.log(t);
											if(t.data.data.refresh == 1){
												window.location.href=`/app/wxapp.php?m=wxz_wzbagent&do=wechat&c=entry&a=wxapp&token=${that.live.token}&xuan_id=${xuan_id}&r=h5login`;
											}
											//var appid = getApp().globalData.siteInfo.appid;
											var pay_params = t.data.data.pay_params;
											let self = this;
											jWeiXin.config({
												debug: false,
												appId: pay_params.appId,
												timestamp: pay_params.timeStamp,
												nonceStr: pay_params.nonceStr,
												signature: pay_params.paySign,
												jsApiList: ['chooseWXPay']
											});
											jWeiXin.ready(function() {
												jWeiXin.checkJsApi({
													jsApiList: ['chooseWXPay'],
													success: function(res) {
														console.log(
															'checkjsapi Success');
														console.log(res);
													},
													fail: function(res) {
														console.log('res');
														console.log(res);
													}
												});
												jWeiXin.chooseWXPay({
													timestamp: pay_params.timeStamp,
													nonceStr: pay_params.nonceStr,
													package: pay_params.package,
													signType: pay_params.signType,
													paySign: pay_params.paySign,
													success: function(res) {
														that.get_vote_info();
														that.payGiftSuccess(t.data.data
															.logsid, t.data.data
															.out_trade_no, index);
														//console.log(res);
													},
													cancel: function(res) {
														//console.log(res)
													},
													fail: function(res) {
														uni.showToast({
															title: '支付失败!',
															icon: 'none',
															duration: 1500
														});
														//console.log(res);
													}
												});
											});

											jWeiXin.error(function(res) {
												console.log(res);
											});
										}
									});
								} else if (!wxopenid) {
									location.reload();
								}
							}
							//#endif
							//#ifndef H5
							uni.login({
								success: function(res) {
									app.globalData.util.request({
										url: 'lives_new&r=payGift',
										data: {
											uid: uid,
											gift_id: gift_id,
											gift_num: gift_num,
											xuan_id: xuan_id,
											voteName: voteName,
											uniacid: that.live.uniacid,
											wxapp_id: that.wxapp_id,
											code: res.code
										},
										cachetime: '0',
										showLoading: 0,
										success: function(t) {
											var pay_params = t.data.data.pay_params;
											uni.requestPayment({
												timeStamp: pay_params.timeStamp,
												nonceStr: pay_params.nonceStr,
												package: pay_params.package,
												signType: pay_params.signType,
												paySign: pay_params.paySign,
												success: function(res) {
													// wx.showToast({
													//     title: '支付成功!',
													//     icon: 'none',
													//     duration: 1500
													// })
													that.payGiftSuccess(t.data.data
														.logsid, t.data.data
														.out_trade_no, index);
												},
												fail: function(res) {
													uni.showToast({
														title: '支付失败!',
														icon: 'none',
														duration: 1500
													});
													// that.payGiftSuccess(t.data.data.logsid,t.data.data.out_trade_no,index);
												},

												complete: function(res) {}
											});
										}
									});
								}
							});
							// #endif
						} else { //支付宝
							app.globalData.util.request({
								url: 'ali&r=payGift',
								data: {
									uid: uid,
									gift_id: gift_id,
									gift_num: gift_num,
									xuan_id: xuan_id,
									voteName: voteName,
									uniacid: that.live.uniacid_ali,
									wxapp_id: that.wxapp_id,
									//code: res.code
								},
								cachetime: '0',
								showLoading: 0,
								success: function(t) {
									// that.tradePay(t.data.data.pay_params.alipay_trade_create_response
									// 	.trade_no)
									window.location.href = t.data.data.pay_params;
								},
								fail: function(err) {
									uni.showToast({
										title: '支付失败！'
									})
								}
							});
						}
					}
				} else {
					uni.showToast({
						title: '请选择礼物!',
						icon: 'none',
						duration: 1500
					});
				}
			},

			//打call付费成功
			payGiftSuccess: function(logsid, out_trade_no, index) {
				var that = this;
				app.globalData.util.request({
					url: 'lives_new&r=payGiftSuccess',
					data: {
						logsid: logsid,
						wxapp_id: that.wxapp_id,
						out_trade_no: out_trade_no
					},
					cachetime: '0',
					showLoading: 0,
					success: function(t) {
						if (t.data.data.s == 1) {
							var zanshu = parseInt(that.data.vote_info.votes) + t.data.data.tickes;
							var key = 'vote_info.votes';
							that.vote_info.votes = zanshu;
							that.bindclosevote();
							uni.showToast({
								title: t.data.data.msg,
								icon: 'none',
								duration: 1500
							});
						}
					}
				});
			},

			//生成海报
			bindSheng: function() {
				var that = this;
				console.log(that.xuan_id, that.token, that.wxapp_id)
				console.log(isWeiXin(), 'isWeiXin()');
				app.globalData.util.request({
					url: isWeiXin() ? 'wechat&r=personal' : 'ali&r=personal',
					data: {
						xuan_id: that.xuan_id,
						token: that.token,
						uid: uni.getStorageSync('uid'),
						wxopenid: uni.getStorageSync('wxopenid'),
						uniacid: uni.getStorageSync('uniacid'),
						// wxapp_id: that.wxapp_id
					},
					showLoading: 0,
					success: function(t) {
						console.log(t)
						if (t.data.errno == 0) {
							var sunEwm = t.data.data.sunEwm;
							var voteBg = t.data.data.voteBg;
							var voteBgActive = t.data.data.voteBgActive;
							that.setData({
								sunEwm: sunEwm,
								voteMaskLi: 1,
								voteBg: voteBg,
								voteBgActive: voteBgActive
							});
						}
					}
				});
			},

			// 关闭海报选择
			voteMaskClose: function(e) {
				if (1 == e.currentTarget.dataset.index) {
					this.setData({
						voteMaskLi: false
						//haibaoimgshow:false
					});
					// location.reload();
				} else {
					this.setData({
						voteMask: false,
						voteMaskLi: true
						//haibaoimgshow:true
					});
					// location.reload();
				}
			},


			voteConvasLi: function(t) {
				var a = t.currentTarget.dataset.index;
				this.setData({
					voteMask: true,
					voteMaskLi: false,
					canvasIndex: a
				});
				e(this, a);
			},

			saveCanvas: function() {
				//#ifndef H5
				n(this);
				//#endif
			},
			//base64 转 Blob对象
			/* base64: ....
			/* Blob：{...}
			*/
			base64ToBlob(data) {
				var arr = data.split(','),
					mime = arr[0].match(/:(.*?);/)[1],
					bstr = atob(arr[1]),
					n = bstr.length,
					u8arr = new Uint8Array(n);
				while (n--) {
					u8arr[n] = bstr.charCodeAt(n);
				}
				return new Blob([u8arr], {
					type: mime
				});
			},
			touchStart() {
				let path = this.canvasFilePaths[this.canvasIndex];
				if (path) { // 接口返回的数据部分
					// 解析图片
					// 因接口直接返回了base64代码部分，所以不需要截取，如果含"data:image/png;base64," 则需要自己做截取处理
					var blob = this.base64ToBlob(path);
					//保存图片
					var aLink = document.createElement('a');
					var evt = document.createEvent("HTMLEvents");
					evt.initEvent("click", true, true);
					aLink.download = this.canvasIndex;
					aLink.href = URL.createObjectURL(blob);
					aLink.click();
				} else {
					console.log('没有base64代码');
				}
				//this.downloadImage(path,this.canvasIndex);
			},
			downloadImage(imgsrc, name) {
				console.log(imgsrc);
				//下载图片地址和图片名
				var image = new Image();
				// 解决跨域 Canvas 污染问题
				image.setAttribute("crossOrigin", "anonymous");
				image.onload = function() {
					// var canvas = document.createElement("canvas");
					// canvas.width = image.width;
					// canvas.height = image.height;
					// var context = canvas.getContext("2d");
					// context.drawImage(image, 0, 0, image.width, image.height);
					// var url = canvas.toDataURL("image/png"); //得到图片的base64编码数据
					var a = document.createElement("a"); // 生成一个a元素
					var event = new MouseEvent("click"); // 创建一个单击事件
					a.download = name || "photo"; // 设置图片名称
					a.href = imgsrc; // 将生成的URL设置为a.href属性
					a.dispatchEvent(event); // 触发a的单击事件
				}
				image.src = imgsrc;
			},
			touchsave: function() {
				var that = this;
				uni.getSetting({
					success: function(t) {
						console.log(t);
						if (t.authSetting['scope.writePhotosAlbum']) {
							d(that);
						} else {
							uni.authorize({
								scope: 'scope.writePhotosAlbum',
								success: function(t) {
									d(that);
								},
								fail: function(t) {
									console.log(t);
									that.setData({
										openSetting: true
									});
								}
							});
						}
					}
				});
			},

			bindopensetting: function(e) {
				console.log(e);
				this.setData({
					openSetting: false
				});
			},

			imgYu: function(event) {
				var src = event.target.dataset.src; //获取data-src
				var urls = [];
				urls[0] = src;
				//图片预览
				uni.previewImage({
					current: src,
					// 当前显示图片的http链接
					urls: urls // 需要预览的图片http链接列表
				});
			},

			// jumpNew: function (e) {
			//     var that = this;
			//     uni.showModal({
			//         title: that.live.jump_title,
			//         content: that.live.jump_content,
			//         showCancel: false,
			//         confirmText: '确定',
			//         success(res) {
			//             if (res.confirm) {
			//                 uni.navigateToMiniProgram({
			//                     appId: that.jump_appid,
			//                     path: '/wxz_wzbagent/pages/vote/vote_info' + '?token=' + that.live.token + '&xuan_id=' + that.vote_info.id,
			//                     success(res) {
			//                         console.log(res);
			//                     },
			//                     fail(res) {
			//                         console.log(res);
			//                     },
			//                     complete(res) {
			//                         console.log(res);
			//                     }
			//                 });
			//             }
			//         }
			//     });
			// }
		}
	};
</script>
<style>
	@import './vote_info.css';
</style>